
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>022常用类 · 书名</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="作者">
        <meta name="identifier" content="图书编号" scheme="ISBN">
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-back-to-top-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-intopic-toc/style.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-flexible-alerts/style.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-theme-comscore/test.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="023File类.html" />
    
    
    <link rel="prev" href="021包装类.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    书名
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">Books</li>
        
        
    
        <li class="chapter " data-level="2.1" >
            
                <span>
            
                    
                    Java
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1.1" data-path="001环境变量.html">
            
                <a href="001环境变量.html">
            
                    
                    001环境变量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.2" data-path="002Java初体验.html">
            
                <a href="002Java初体验.html">
            
                    
                    002Java初体验
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.3" data-path="003变量命名及数据类型.html">
            
                <a href="003变量命名及数据类型.html">
            
                    
                    003变量命名及数据类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.4" data-path="004运算符.html">
            
                <a href="004运算符.html">
            
                    
                    004运算符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.5" data-path="005选择结构.html">
            
                <a href="005选择结构.html">
            
                    
                    005选择结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.6" data-path="006循环结构.html">
            
                <a href="006循环结构.html">
            
                    
                    006循环结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.7" data-path="007数组.html">
            
                <a href="007数组.html">
            
                    
                    007数组
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.8" data-path="008类和对象方法.html">
            
                <a href="008类和对象方法.html">
            
                    
                    008类和对象方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.9" data-path="009构造方法.html">
            
                <a href="009构造方法.html">
            
                    
                    009构造方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.10" data-path="010封装与关键字static.html">
            
                <a href="010封装与关键字static.html">
            
                    
                    010封装与关键字Static
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.11" data-path="011 继承.html">
            
                <a href="011 继承.html">
            
                    
                    011 继承
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.12" data-path="012方法重写.html">
            
                <a href="012方法重写.html">
            
                    
                    012方法重写
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.13" data-path="013多态.html">
            
                <a href="013多态.html">
            
                    
                    013多态
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.14" data-path="014抽象类抽象方法.html">
            
                <a href="014抽象类抽象方法.html">
            
                    
                    014抽象类抽象方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.15" data-path="015接口.html">
            
                <a href="015接口.html">
            
                    
                    015接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.16" data-path="016异常.html">
            
                <a href="016异常.html">
            
                    
                    016异常
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.17" data-path="017集合.html">
            
                <a href="017集合.html">
            
                    
                    017集合
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.18" data-path="017集合2.html">
            
                <a href="017集合2.html">
            
                    
                    017集合2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.19" data-path="018泛型.html">
            
                <a href="018泛型.html">
            
                    
                    018泛型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.20" data-path="019Collections算法类.html">
            
                <a href="019Collections算法类.html">
            
                    
                    019Collections算法类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.21" data-path="020枚举.html">
            
                <a href="020枚举.html">
            
                    
                    020枚举
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.22" data-path="021包装类.html">
            
                <a href="021包装类.html">
            
                    
                    021包装类
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="2.1.23" data-path="022常用类.html">
            
                <a href="022常用类.html">
            
                    
                    022常用类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.24" data-path="023File类.html">
            
                <a href="023File类.html">
            
                    
                    023File类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.25" data-path="024IO流.html">
            
                <a href="024IO流.html">
            
                    
                    024IO流
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.26" data-path="025多线程.html">
            
                <a href="025多线程.html">
            
                    
                    025多线程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.27" data-path="025多线程线程池.html">
            
                <a href="025多线程线程池.html">
            
                    
                    025多线程线程池
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.28" data-path="026网络编程Socket.html">
            
                <a href="026网络编程Socket.html">
            
                    
                    026网络编程Socket
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.29" data-path="027XML解析.html">
            
                <a href="027XML解析.html">
            
                    
                    027XML解析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.30" data-path="028 注解.html">
            
                <a href="028 注解.html">
            
                    
                    028 注解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.31" data-path="029 Lambda表达式.html">
            
                <a href="029 Lambda表达式.html">
            
                    
                    029 Lambda表达式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.32" data-path="029 反射.html">
            
                <a href="029 反射.html">
            
                    
                    029 反射
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.2" >
            
                <span>
            
                    
                    Mybatis
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.2.1" data-path="../mybatis/MyBatis.html">
            
                <a href="../mybatis/MyBatis.html">
            
                    
                    MyBatis
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.2.1.1" >
            
                <span>
            
                    
                    MyBatis
            
                </span>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.3" >
            
                <span>
            
                    
                    Mysql
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.3.1" data-path="../mysql/01 SQL通用语法.html">
            
                <a href="../mysql/01 SQL通用语法.html">
            
                    
                    01 SQL通用语法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.2" data-path="../mysql/02 DDL.html">
            
                <a href="../mysql/02 DDL.html">
            
                    
                    02 DDL
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.3" data-path="../mysql/03 DML.html">
            
                <a href="../mysql/03 DML.html">
            
                    
                    03 DML
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.4" data-path="../mysql/04 DQL.html">
            
                <a href="../mysql/04 DQL.html">
            
                    
                    04 DQL
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.5" data-path="../mysql/05 DCL.html">
            
                <a href="../mysql/05 DCL.html">
            
                    
                    05 DCL
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.6" data-path="../mysql/06 函数.html">
            
                <a href="../mysql/06 函数.html">
            
                    
                    06 函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.7" data-path="../mysql/07 约束.html">
            
                <a href="../mysql/07 约束.html">
            
                    
                    07 约束
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.8" data-path="../mysql/08 多表查询.html">
            
                <a href="../mysql/08 多表查询.html">
            
                    
                    08 多表查询
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.9" data-path="../mysql/09 事务.html">
            
                <a href="../mysql/09 事务.html">
            
                    
                    09 事务
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.10" data-path="../mysql/999zzz.html">
            
                <a href="../mysql/999zzz.html">
            
                    
                    999zzz
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.11" data-path="../mysql/MySql.html">
            
                <a href="../mysql/MySql.html">
            
                    
                    MySql
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.12" data-path="../mysql/sql.html">
            
                <a href="../mysql/sql.html">
            
                    
                    Sql
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.4" >
            
                <span>
            
                    
                    Spring
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.4.1" data-path="../spring/spring.html">
            
                <a href="../spring/spring.html">
            
                    
                    Spring
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.5" >
            
                <span>
            
                    
                    SpringMVC
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.5.1" data-path="../springMVC/springMVC.html">
            
                <a href="../springMVC/springMVC.html">
            
                    
                    SpringMVC
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.6" >
            
                <span>
            
                    
                    整合
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.6.1" data-path="../整合/Mybatis框架.html">
            
                <a href="../整合/Mybatis框架.html">
            
                    
                    Mybatis框架
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.2" data-path="../整合/SpringBoot.html">
            
                <a href="../整合/SpringBoot.html">
            
                    
                    SpringBoot
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.3" data-path="../整合/springmvc框架.html">
            
                <a href="../整合/springmvc框架.html">
            
                    
                    Springmvc框架
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.4" data-path="../整合/spring框架.html">
            
                <a href="../整合/spring框架.html">
            
                    
                    Spring框架
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >022常用类</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="random">Random</h1>
<p><img src="images/022&#x5E38;&#x7528;&#x7C7B;/image-20220815150315463.png" alt="image-20220815150315463"></p>
<p>java.util.Random&#x7C7B;</p>
<pre><code class="lang-java">Random rand = <span class="hljs-keyword">new</span> Random(); <span class="hljs-comment">// &#x521B;&#x5EFA;&#x4E00;&#x4E2A;Random&#x5BF9;&#x8C61;</span>
<span class="hljs-keyword">for</span>(<span class="hljs-keyword">int</span> i=<span class="hljs-number">0</span>; i&lt;<span class="hljs-number">20</span>; i++){
    <span class="hljs-keyword">int</span> num = rand.nextInt(<span class="hljs-number">10</span>); <span class="hljs-comment">// &#x8FD4;&#x56DE;&#x4E0B;&#x4E00;&#x4E2A;&#x4F2A;&#x968F;&#x673A;&#x6570;,&#x6574;&#x578B;</span>
    System.out.println(num)
}
</code></pre>
<h1 id="string">String</h1>
<p><img src="images/022&#x5E38;&#x7528;&#x7C7B;/image-20220815185403795.png" alt="image-20220815185403795"></p>
<blockquote>
<p>string &#x7C7B;&#x63D0;&#x4F9B;&#x4E86;&#x786E;&#x5B9A;&#x5B57;&#x7B26;&#x4E32;&#x957F;&#x5EA6;&#x7684;&#x65B9;&#x6CD5; length()</p>
<p>equals() &#x65B9;&#x6CD5;, &#x6BD4;&#x8F83;&#x5B58;&#x50A8;&#x5728;&#x4E24;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x5185;&#x5BB9;&#x662F;&#x5426;&#x4E00;&#x81F4;</p>
</blockquote>
<p><strong>== &#x548C; equals() &#x533A;&#x522B;</strong>
== &#x5224;&#x65AD;&#x4E24;&#x4E2A;&#x81EA;&#x6E21;&#x8239;&#x5728;&#x5185;&#x5B58;&#x4E2D;&#x7684;&#x5730;&#x5740;, &#x53CA;&#x5224;&#x65AD;&#x662F;&#x5426;&#x4E3A;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#x5BF9;&#x8C61;</p>
<p><strong>&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x5176;&#x4ED6;&#x65B9;&#x6CD5;</strong>
equalsIgnoreCase() &#x65B9;&#x6CD5; --&gt; &#x5B57;&#x7B26;&#x4E32;&#x6BD4;&#x8F83;&#x5FFD;&#x7565;&#x5927;&#x5C0F;&#x5199;</p>
<p>toLowerCase() &#x65B9;&#x6CD5; --&gt; &#x5C06;&#x5B57;&#x7B26;&#x4E32;&#x5B57;&#x6BCD;&#x5168;&#x90E8;&#x8F6C;&#x6362;&#x6210;&#x5C0F;&#x5199;</p>
<p>toUpperCase() &#x65B9;&#x6CD5; --&gt; &#x5C06;&#x5B57;&#x7B26;&#x4E32;&#x5B57;&#x6BCD;&#x5168;&#x90E8;&#x8F6C;&#x6362;&#x6210;&#x5927;&#x5199;</p>
<p><strong>&#x5B57;&#x7B26;&#x4E32;&#x8FDE;&#x63A5;</strong>
&#x65B9;&#x6CD5;1: &#x4F7F;&#x7528; &quot; + &quot;</p>
<p>&#x65B9;&#x6CD5;2: &#x4F7F;&#x7528; String&#x7C7B; &#x7684; concat() &#x65B9;&#x6CD5;</p>
<table>
<thead>
<tr>
<th style="text-align:left">&#x65B9;&#x6CD5;&#x540D;</th>
<th style="text-align:left">&#x63CF;&#x8FF0;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">int indexOf(int ch)</td>
<td style="text-align:left">&#x901A;&#x8FC7;ASCII&#x7801;&#x5728;&#x5B57;&#x7B26;&#x4E32;&#x4E2D;&#x627E;&#x5BF9;&#x5E94;&#x7684;&#x5B57;&#x6BCD;&#x4E0B;&#x6807;</td>
</tr>
<tr>
<td style="text-align:left">int indexOf(String value)</td>
<td style="text-align:left">&#x5728;&#x5B57;&#x7B26;&#x4E32;&#x4E2D;&#x627E;&#x5B57;&#x7B26;,&#x8FD4;&#x56DE;&#x7B2C;&#x4E00;&#x4E2A;&#x4E0B;&#x6807;</td>
</tr>
<tr>
<td style="text-align:left">int lastIndexof(int ch)</td>
<td style="text-align:left">&#x4ECE;&#x540E;&#x9762;&#x5F00;&#x59CB;&#x627E;...</td>
</tr>
<tr>
<td style="text-align:left">int lastIndexOf(String value)</td>
<td style="text-align:left">&#x4ECE;&#x540E;&#x9762;&#x5F00;&#x59CB;&#x627E;...</td>
</tr>
<tr>
<td style="text-align:left">String substring(int index)</td>
<td style="text-align:left">&#x622A;&#x53D6;&#x5B57;&#x7B26;&#x4E32;</td>
</tr>
<tr>
<td style="text-align:left">String substring(int beginindex, int endindex)</td>
<td style="text-align:left">&#x6307;&#x5B9A;&#x4F4D;&#x7F6E;&#x622A;&#x53D6;&#x5B57;&#x7B26;&#x4E32;</td>
</tr>
<tr>
<td style="text-align:left">String trim()</td>
<td style="text-align:left">&#x53BB;&#x9664;&#x5B57;&#x7B26;&#x4E32;&#x524D;&#x540E;&#x7684;&#x7A7A;&#x683C;</td>
</tr>
<tr>
<td style="text-align:left">String[] split()</td>
<td style="text-align:left">&#x5B57;&#x7B26;&#x4E32;&#x5206;&#x5272;</td>
</tr>
</tbody>
</table>
<h1 id="stringbuffer">StringBuffer</h1>
<blockquote>
<p>&#x5BF9;&#x5B57;&#x7B26;&#x4E32;&#x9891;&#x7E41;&#x4FEE;&#x6539;(&#x5982; &#x5B57;&#x7B26;&#x4E32;&#x8FDE;&#x63A5; )&#x65F6;, &#x4F7F;&#x7528; StringBuffer&#x7C7B;&#x53EF;&#x4EE5;&#x6253;&#x6253;&#x63D0;&#x9AD8;&#x7A0B;&#x5E8F;&#x6267;&#x884C;&#x6548;&#x7387;</p>
</blockquote>
<p><strong>StringBuffer&#x58F0;&#x660E;</strong></p>
<pre><code class="lang-java">StringBuffer strb = <span class="hljs-keyword">new</span> StringBuffer();
StringBuffer strb = <span class="hljs-keyword">new</span> StringBuffer(<span class="hljs-string">&quot;aaa&quot;</span>);
</code></pre>
<p><strong>StringBuffer&#x7684;&#x4F7F;&#x7528;</strong></p>
<pre><code class="lang-java">strb.toString(); <span class="hljs-comment">// &#x8F6C;&#x5316;&#x8F6C;&#x4E3A;String&#x7C7B;&#x578B;</span>
strb.append(<span class="hljs-string">&quot;**&quot;</span>); <span class="hljs-comment">// &#x8FFD;&#x52A0;&#x5B57;&#x7B26;&#x4E32;</span>
strb.insert(<span class="hljs-number">1</span>,<span class="hljs-string">&quot;**&quot;</span>);
</code></pre>
<p>String &#x662F;&#x4E0D;&#x53EF;&#x53D8;&#x5B57;&#x7B26;&#x4E32;</p>
<p>&#x7ECF;&#x5E38;&#x6539;&#x53D8;&#x5185;&#x5BB9;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x6700;&#x597D;&#x4E0D;&#x8981;&#x4F7F;&#x7528;String</p>
<p>StringBuffer&#x662F;&#x53EF;&#x53D8;&#x5B57;&#x7B26;&#x4E32;</p>
<p>&#x5B57;&#x7B26;&#x4E32;&#x7ECF;&#x5E38;&#x6539;&#x53D8;&#x7684;&#x60C5;&#x51B5;&#x53EF;&#x4F7F;&#x7528;StringBuffer</p>
<p>(JDK5 &#x63D0;&#x4F9B;&#x4E86;StringBuilder, &#x7B49;&#x4EF7; StringBuffer)</p>
<h1 id="date">Date</h1>
<p>java.util.Date&#x7C7B;: &#x8868;&#x793A;&#x65E5;&#x671F;&#x548C;&#x65F6;&#x95F4;</p>
<p>&#x63D0;&#x4F9B;&#x65E5;&#x671F;&#x548C;&#x65F6;&#x95F4;&#x5404;&#x7EC4;&#x6210;&#x90E8;&#x5206;&#x7684;&#x65B9;&#x6CD5;</p>
<pre><code class="lang-java"><span class="hljs-comment">// &#x521B;&#x5EFA;&#x65E5;&#x671F;&#x5BF9;&#x8C61;</span>
Date data = <span class="hljs-keyword">new</span> Date();
<span class="hljs-comment">// &#x5B9A;&#x5236;&#x65E5;&#x671F;&#x683C;&#x5F0F;</span>
SimpleDateFormate formater = <span class="hljs-keyword">new</span> SimpleDateFormat(<span class="hljs-string">&quot;yyyy-MM-dd HH:mm:ss&quot;</span>);
String now = formater.format(date);
System.out.println(now);
</code></pre>
<h1 id="calendar">Calendar</h1>
<p>&#x62BD;&#x8C61;&#x7C7B;, <code>java.util.Calendar</code></p>
<p>&#x7528;&#x4E8E;&#x8BBE;&#x7F6E;&#x548C;&#x83B7;&#x53D6;&#x65E5;&#x671F;/&#x65F6;&#x95F4;&#x6570;&#x636E;&#x7684;&#x5F85;&#x5B9A;&#x90E8;&#x5206;</p>
<table>
<thead>
<tr>
<th>&#x65B9;&#x6CD5;&#x6216;&#x5C5E;&#x6027;</th>
<th>&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td>int get(int field)</td>
<td>&#x8FD4;&#x56DE;&#x7ED9;&#x5B9A;&#x65E5;&#x5386;&#x5B57;&#x6BB5;&#x7684;&#x503C;</td>
</tr>
<tr>
<td>MONTH</td>
<td>&#x6307;&#x793A;&#x6708;</td>
</tr>
<tr>
<td>DAY_OF_MONTH</td>
<td>&#x6307;&#x793A;&#x4E00;&#x4E2A;&#x6708;&#x4E2D;&#x7684;&#x67D0;&#x5929;</td>
</tr>
<tr>
<td>DAY_OF_WEEK</td>
<td>&#x6307;&#x793A;&#x4E00;&#x4E2A;&#x661F;&#x671F;&#x4E2D;&#x7684;&#x67D0;&#x5929;</td>
</tr>
</tbody>
</table>
<p>Calendar&#x7C7B;&#x53EB;&#xFF1A;&#x65E5;&#x5386;&#x7C7B;&#xFF0C;&#x662F;&#x65B9;&#x4FBF;&#x6211;&#x4EEC;&#x64CD;&#x4F5C;&#x65E5;&#x671F;&#x7684;&#xFF0C;&#x5B83;&#x91CC;&#x9762;&#x7684;&#x529F;&#x80FD;&#x5927;&#x591A;&#x6570;&#x662F;&#x7528;&#x6765;&#x66FF;&#x4EE3;<code>java.util.Date</code>&#x7C7B;&#x7684;&#x529F;&#x80FD;&#x7684;</p>
<p><strong>&#x4E8C;&#x3001;&#x6784;&#x9020;&#x65B9;&#x6CD5;</strong>
Calendar&#x7C7B;&#x53EF;&#x4EE5;&#x7406;&#x89E3;&#x4E3A;&#x662F;&#x5DE5;&#x5177;&#x7C7B;&#xFF0C;&#x56E0;&#x4E3A;&#x5B83;&#x662F;&#x4E00;&#x4E2A;&#x62BD;&#x8C61;&#x7C7B;&#xFF0C;&#x6240;&#x6709;&#x5916;&#x754C;&#x65E0;&#x6CD5;&#x901A;&#x8FC7;new&#x7684;&#x65B9;&#x5F0F;&#x521B;&#x5EFA;&#x672C;&#x7C7B;&#x5BF9;&#x8C61;</p>
<p>&#x901A;&#x8FC7;Calendar#<code>getInstance</code>()&#x65B9;&#x6CD5;&#x5B9E;&#x73B0;
&#x5B9E;&#x4F8B;:</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Test</span> </span>{
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>{
        Calendar C = Calendar.getInstance();
        System.out.println(C.getTime());
    }
}
</code></pre>
<p><strong>&#x4E09;&#x3001;&#x6210;&#x5458;&#x53D8;&#x91CF;</strong></p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">int</span> YEAR&#xFF1A;&#x8868;&#x793A;&#x5E74;&#x4EFD;
<span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">int</span> MONT&#xFF1A;&#x8868;&#x793A;&#x6708;&#x4EFD;
<span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">int</span> DATE&#xFF1A;&#x8868;&#x793A;&#x5E74;&#x7EC8;&#x7684;&#x67D0;&#x4E00;&#x5929;
<span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">int</span> DAYOFMONTH&#xFF1A;&#x8868;&#x793A;&#x6708;&#x4E2D;&#x7684;&#x67D0;&#x4E00;&#x5929;
<span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">int</span> DAYOFWEEK&#xFF1A;&#x8868;&#x793A;&#x661F;&#x671F;&#x4E2D;&#x7684;&#x67D0;&#x4E00;&#x5929;
</code></pre>
<p><strong>&#x56DB;&#x3001;&#x6210;&#x5458;&#x65B9;&#x6CD5;</strong></p>
<pre><code class="lang-java"><span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> Calendar <span class="hljs-title">getInstance</span><span class="hljs-params">()</span>&#xFF1A;&#x521B;&#x5EFA;Calendar&#x7C7B;&#x578B;&#x7684;&#x5B50;&#x7C7B;&#x5BF9;&#x8C61;
<span class="hljs-keyword">public</span> <span class="hljs-keyword">int</span> <span class="hljs-title">get</span><span class="hljs-params">(<span class="hljs-keyword">int</span> field)</span>&#xFF1A;&#x6839;&#x636E;&#x65E5;&#x5386;&#x5B57;&#x6BB5;&#xFF0C;&#x83B7;&#x53D6;&#x5176;&#x5BF9;&#x5E94;&#x7684;&#x503C;
<span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">set</span><span class="hljs-params">(<span class="hljs-keyword">int</span> year, <span class="hljs-keyword">int</span> month, <span class="hljs-keyword">int</span> day)</span>&#xFF1A;&#x8BBE;&#x7F6E;&#x65F6;&#x95F4;&#x4E3A;&#x6307;&#x5B9A;&#x7684;&#x5E74;&#xFF0C;&#x6708;&#xFF0C;&#x65E5;
<span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">add</span><span class="hljs-params">(<span class="hljs-keyword">int</span> field, <span class="hljs-keyword">int</span> count)</span>&#xFF1A;&#x4FEE;&#x6539;&#x6307;&#x5B9A;&#x7684;&#x65F6;&#x95F4;&#x4E3A;&#x6307;&#x5B9A;&#x7684;&#x504F;&#x79FB;&#x91CF;
&#x4F8B;&#x5982;&#xFF1A;&#x5F80;&#x524D;&#x63A8;2&#x5929;&#xFF0C;&#x63A8;3&#x4E2A;&#x6708;&#xFF0C;&#x5F80;&#x540E;&#x63A8;2&#x5E74;
</span></code></pre>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="021包装类.html" class="navigation navigation-prev " aria-label="Previous page: 021包装类">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="023File类.html" class="navigation navigation-next " aria-label="Next page: 023File类">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"022常用类","level":"2.1.23","depth":2,"next":{"title":"023File类","level":"2.1.24","depth":2,"path":"books/java/023File类.md","ref":"books/java/023File类.md","articles":[]},"previous":{"title":"021包装类","level":"2.1.22","depth":2,"path":"books/java/021包装类.md","ref":"books/java/021包装类.md","articles":[]},"dir":"ltr"},"config":{"plugins":["search-pro","code","back-to-top-button","theme-comscore","intopic-toc","flexible-alerts","expandable-chapters"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"intopic-toc":{"selector":".markdown-section h1, .markdown-section h2, .markdown-section h3, .markdown-section h4, .markdown-section h5, .markdown-section h6","mode":"nested","maxDepth":6,"isCollapsed":true,"isScrollspyActive":true,"visible":true,"label":"In this article"},"search-pro":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"code":{"copyButtons":true},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"theme-comscore":{},"back-to-top-button":{},"flexible-alerts":{"style":"callout","note":{"label":"Note","icon":"fa fa-info-circle","className":"info"},"tip":{"label":"Tip","icon":"fa fa-lightbulb-o","className":"tip"},"warning":{"label":"Warning","icon":"fa fa-exclamation-triangle","className":"warning"},"danger":{"label":"Attention","icon":"fa fa-ban","className":"danger"}},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"expandable-chapters":{}},"theme":"default","author":"作者","lang":"zh-cn","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"isbn":"图书编号","variables":{},"title":"书名","gitbook":"*","description":"描述"},"file":{"path":"books/java/022常用类.md","mtime":"2022-08-16T08:34:50.096Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2023-03-01T12:24:55.135Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-back-to-top-button/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-intopic-toc/anchor.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-intopic-toc/gumshoe.polyfills.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-intopic-toc/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-flexible-alerts/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-theme-comscore/test.js"></script>
        
    

    </body>
</html>

